package com.example.myapplication.db.room.dao;

import android.content.Context;
import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import androidx.room.TypeConverters;
import com.example.myapplication.converters.DateConverters;
import com.example.myapplication.db.room.entity.CalculationParameters;

@Database(entities = {CalculationParameters.class}, version = 1,exportSchema = false)
@TypeConverters(DateConverters.class)
public abstract class MyAppDatabase extends RoomDatabase {
    public abstract CalculationParametersDao calculationParametersDao();
    private static volatile MyAppDatabase INSTANCE;

    public static synchronized MyAppDatabase getInstance(Context context) {
        if (INSTANCE == null) {
            INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
                            MyAppDatabase.class, "my-database-name")
                    .allowMainThreadQueries()
                    .fallbackToDestructiveMigration()
                    .fallbackToDestructiveMigrationOnDowngrade()
                    .build();
        }
        return INSTANCE;
    }
}
